/**
 * 报表设计公司(2011)
 */
package com.reportgear.report.setting;

import org.dom4j.Element;

import com.reportgear.core.api.XmlSerializerWithReadReturn;
import com.reportgear.report.model.headerfooter.ReportHF;
import com.sot.core.util.NumberUtils;

/**
 * 报表核心-模型配置
 * 
 * @version 1.0 2011-3-23
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since ANNCSR 2.0
 */
public class ReportSettings implements XmlSerializerWithReadReturn<ReportSettings> {
	public static final String XML_TAG = "reportSettings";
	// 默认报表模型配置
	// public static final ReportSettings DEFAULT_SETTINGS = new
	// ReportSettings();

	// 纸张设置
	private PaperSetting paperSetting = new PaperSetting();
	// 报表页眉
	private ReportHF header = new ReportHF();
	// 报表页脚
	private ReportHF footer = new ReportHF();

	// TODO 增加报表背景
	// TODO 增加是否打印背景
	// TOOD 增加是否预览背景
	// TODO 增加报表方向

	/**
	 * @return 获取页眉高度
	 */
	public double getHeaderHeight() {
		return this.header.getHeight();
	}

	/**
	 * @return 获取页脚高度
	 */
	public double getFooterHeight() {
		return this.footer.getHeight();
	}

	public void setPaperSetting(PaperSetting paramPaperSetting) {
		this.paperSetting = paramPaperSetting;
	}

	public PaperSetting getPaperSetting() {
		return this.paperSetting;
	}

	public void setHeader(ReportHF header) {
		this.header = header;
	}

	public ReportHF getHeader() {
		return header;
	}

	public void setFooter(ReportHF footer) {
		this.footer = footer;
	}

	public ReportHF getFooter() {
		return footer;
	}

	public ReportSettings clone() {
		try {
			ReportSettings reportSettings = (ReportSettings) super.clone();

			return reportSettings;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public ReportSettings read(Element parent) {
		if (parent == null) {
			return this;
		}

		this.header.read(parent.element(ReportHF.XML_TAG_HEADER));
		this.footer.read(parent.element(ReportHF.XML_TAG_FOOTER));
		this.paperSetting.read(parent.element(PaperSetting.XML_TAG));

		return this;
	}

	@Override
	public void write(Element parent) {
		if (parent == null) {
			return;
		}

		Element el;
		el = parent.addElement(ReportHF.XML_TAG_HEADER);
		this.header.write(el);

		el = parent.addElement(ReportHF.XML_TAG_FOOTER);
		this.footer.write(el);

		el = parent.addElement(PaperSetting.XML_TAG);
		this.paperSetting.write(el);
	}
}
